package com.isunland.managesystem.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.ProductLedgerOriginal.ProductLedgerContent;
import java.util.List;

public class PriceListAdapter extends ArrayAdapter<ProductLedgerContent> {
  private static class ViewHolder {
    public final LinearLayout rootView;
    public final TextView tvpriceCondition;
    public final TextView tvpriceApartment;
    public final TextView tvpriceMoney;

    private ViewHolder(LinearLayout rootView, TextView tvpriceCondition, TextView tvpriceApartment,
        TextView tvpriceMoney) {
      this.rootView = rootView;
      this.tvpriceCondition = tvpriceCondition;
      this.tvpriceApartment = tvpriceApartment;
      this.tvpriceMoney = tvpriceMoney;
    }

    public static ViewHolder create(LinearLayout rootView) {
      TextView tvpriceCondition = (TextView) rootView.findViewById(R.id.tv_price_condition);
      TextView tvpriceApartment = (TextView) rootView.findViewById(R.id.tv_price_apartment);
      TextView tvpriceMoney = (TextView) rootView.findViewById(R.id.tv_price_money);
      return new ViewHolder(rootView, tvpriceCondition, tvpriceApartment, tvpriceMoney);
    }
  }

  @Override public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder vh;
    if (convertView == null) {
      View view = mInflater.inflate(R.layout.adapter_price_list, parent, false);
      vh = ViewHolder.create((LinearLayout) view);
      view.setTag(vh);
    } else {
      vh = (ViewHolder) convertView.getTag();
    }

    ProductLedgerContent item = getItem(position);
    if (item.getSaleCondition() != null) {
      vh.tvpriceCondition.setText(item.getSaleCondition().toString());//价格条件
    } else {
      vh.tvpriceCondition.setText("");//价格条件
    }
    if (item.getCustomerName() != null) {
      vh.tvpriceApartment.setText(item.getCustomerName().toString());//客户/部门
    } else {
      vh.tvpriceApartment.setText("");//客户/部门
    }
    if (item.getSalePrice() != null) {
      vh.tvpriceMoney.setText(item.getSalePrice().toString());//价格
    } else {
      vh.tvpriceMoney.setText("");//价格
    }
    return vh.rootView;
  }

  private LayoutInflater mInflater;

  // Constructors
  public PriceListAdapter(Context context, List<ProductLedgerContent> objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
  }

  public PriceListAdapter(Context context, ProductLedgerContent[] objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
  }

  /**
   * listview为空时显示header。只要返回false就可以了。
   * 表示listView不会空。
   * @see android.widget.BaseAdapter#isEmpty()
   */
  //	@Override
  //	public boolean isEmpty() {
  //
  //		return false;
  //	}
}

